import httpInstance from "@/utils/http.js";

//根据gid获取商品详细信息
export function getGoodsDetailAPI(gid){
    return httpInstance({
        //url:`/goods/selectGoodsByGid/gid=${gid}`,
        url:`/goods/${gid}/detail`,
        method:'get',
        headers: {
            'Content-Type': 'multipart/form-data',
        }
    })
}

//获取种类名查询商品
export function getGoodsByCategoryAPI(keyword,pageNum,pageSize){
    return httpInstance({
        url:'/goods/pageForCategory/category',
        method:'get',
        params:{
            category:keyword,
            pageNum:pageNum,
            pageSize:pageSize
        }
    })
}


//获取商品类目
export function getGoodsCategoriesAPI(){
    return httpInstance({
        url:'/goods/tree',
        //url:'https://apifoxmock.com/m2/5341936-5012878-default/236304689?apifoxApiId=236304689',
        method:'get',
    })
}

//获取指定店铺下的所有商品
export function getGoodsByShopIdAPI(shopId){
    return httpInstance({
        url:'/goods',
        method:'get',
        params:{
            shopID:shopId
        }
    })
}

//发布商品
export function releaseGoodsAPI(goodsFormData){
    return httpInstance({
        url:'/goods/newGoods',
        method:'post',
        data:goodsFormData,
        headers: {
            'Content-Type': 'multipart/form-data;charset=utf-8',
        }
    })
}

//删除商品
export function deleteGoodsAPI(gid){
    return httpInstance({
        url:'/goods/deleteGoods',
        method:'delete',
        params:{
            gid:gid
        }
    })
}

//修改商品信息
export function updateGoodsAPI(goodsFormData){
    return httpInstance({
        url:'/goods/updateGoods',
        method:'post',
        data:goodsFormData,
        headers: {
            'Content-Type': 'multipart/form-data;charset=utf-8',
        }
    })
}

//下载商品图片
export function downloadImagesAPI(url){
    return httpInstance({
        url:url,
        method:'get',
        //responseType: 'arraybuffer' // 设置响应类型为arraybuffer，以获取二进制数据
        dataType: "jsonp",
        jsonp: "callback",
        jsonpCallback: "f",
        success: function (res) {
            console.log(res);
        },
    })
}

//评价商品
export function evaluateGoodsAPI(evaluationData){
    const formData = new FormData()
    formData.append('evaluation', JSON.stringify(evaluationData))
    
    return httpInstance({
        url:'/goods/evaluate',
        method:'post',
        data: formData,
        headers: {
            'Content-Type': 'multipart/form-data;charset=utf-8',
        }
    })
}

//获取商品评价列表
export function getGoodsEvaluationAPI(gid){
    return httpInstance({
        url:'/goods/evaluation',
        method:'get',
        params:{
            gid: gid
        }
    })
}